package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * Author：毕龙
 * Date: 2023/7/27 10:41
 */
@WebServlet("/request")
public class ServletRequestTest extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {

        //处理中请求的文乱码
        request.setCharacterEncoding("utf-8");

        String method = request.getMethod();
        System.out.println("请求的方法："+method);
        StringBuffer url = request.getRequestURL();
        System.out.println("获取请求的路径："+url);
        String uri = request.getRequestURI();
        System.out.println("获取请求的资源："+uri);
        String string = request.getQueryString();
        System.out.println("获取请求的参数："+string);
        String protocol = request.getProtocol();
        System.out.println("获取http的版本："+protocol);

        //获取参数名
        String name = request.getParameter("name");
        System.out.println(name);
        String sex = request.getParameter("sex");
        System.out.println(sex);
        String[] hobbies = request.getParameterValues("hobby");
        System.out.println(Arrays.toString(hobbies));


    }
}
